#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
int a, ans, f[N], n;
char s[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[1] = 0;
  for (int i = 2; i <= n; ++i) {
    if (s[i] == '(' || s[i] == '[' || s[i] == '{') continue;
    if ((s[i - 1 - f[i - 1]] == '(' && s[i] == ')') ||
        (s[i - 1 - f[i - 1]] == '[' && s[i] == ']') ||
        (s[i - 1 - f[i - 1]] == '{' && s[i] == '}')) {
      f[i] = f[i - 1] + 2 + (i - 2 - f[i - 1] ? f[i - 2 - f[i - 1]] : 0);
      ans = max(ans, f[i]);
    }
  }
  cout << ans << endl;
}
